<?php
	header("Content-type: application/x-javascript");
	require_once (dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))) . '/config/cConfig.php';

	$config = new \ampleharvest\cConfig();
	require_once $config->C_STR_AMPLEHARVEST_CODE . "/classes/Tables/cTABLE_Drop_Down.php";

	$obj_TABLE_Drop_Down = new cTABLE_Drop_Down();
?>
Ext.define('AmpleHarvestPHP.objects.search.results.panel.cSort',
{
	extend				: 'Ext.form.Panel',
	autoHeight			: true,
	frame				: true,
	layout				:
	{
		type			: 'hbox',
		defaultMargins	:
		{
			top		: 0,
			right	: 0,
			bottom	: 0,
			left	: 5
		}
	},
	requires			:
	[
			"Ext.form.field.ComboBox",

			"AmpleHarvest.DATA.Store.cDropDown"
	],

	initComponent		: function()
	{
		var obj_This = this;

		this.m_obj_Sort = Ext.create("Ext.form.field.ComboBox",
				{
					fieldLabel		: "Sort By",
					labelWidth		: 45,
					disabled		: true,
					name			: "Sort",
					autoSelect		: true,
					typeAhead		: true,
					forceSelection	: true,
					flex			: 1,
					queryMode		: 'local',
					displayField	: 'Label',
					valueField		: 'Value',
					value			: "score",
					store			: Ext.create(
							"AmpleHarvest.DATA.Store.cDropDown",
							{
								autoLoad	: true
							}
					)
				});

		this.m_obj_Sort.store.on("load", function()
				{
					this.m_obj_Sort.setValue("score");
				}, this);

		this.m_obj_Sort.on("select", function()
				{
					obj_This.ownerCt.do_Search();
				});

		this.m_obj_Direction = Ext.create("Ext.form.field.ComboBox",
				{
					fieldLabel		: "Direction",
					labelWidth		: 50,
					name			: "Direction",
					disabled		: true,
					autoSelect		: true,
					typeAhead		: true,
					queryMode		: 'local',
					displayField	: 'Label',
					flex			: 1,
					valueField		: 'Value',
					store			: Ext.create(
							"AmpleHarvest.DATA.Store.cDropDown",
							{
								autoLoad	: true
							}
					)
				});

		this.m_obj_Direction.store.on("load", function()
				{
					this.m_obj_Direction.setValue("desc");
				}, this);
		this.m_obj_Direction.on("select", function()
				{
					obj_This.ownerCt.do_Search();
				});

		this.m_obj_Layout = Ext.create("Ext.form.field.ComboBox",
				{
					fieldLabel		: "Layout",
					labelWidth		: 50,
					name			: "Layout",
					autoSelect		: true,
					disabled		: true,
					typeAhead		: true,
					queryMode		: 'local',
					displayField	: 'Label',
					flex			: 1,
					valueField		: 'Value',
					store			: Ext.create(
							"AmpleHarvest.DATA.Store.cDropDown",
							{
								autoLoad	: true
							}
					)
				});

		this.m_obj_Layout.store.on("load", function()
				{
					this.m_obj_Layout.setValue("standard");
				}, this);
		this.m_obj_Layout.on("select", function()
				{
					obj_This.ownerCt.do_Search();
				});

		this.m_obj_Sort.store.set_ExtraParams(
		{
			<?php
	print($obj_TABLE_Drop_Down->get_Column_Name($obj_TABLE_Drop_Down->m_int_COL_ID));
?>	: "<?php print(cTABLE_Drop_Down::C_STR_DROPDOWN_SORT_OPTIONS); ?>"
		}
		);

		this.m_obj_Direction.store.set_ExtraParams(
		{
			<?php
	print($obj_TABLE_Drop_Down->get_Column_Name($obj_TABLE_Drop_Down->m_int_COL_ID));
?>	: "<?php print(cTABLE_Drop_Down::C_STR_DROPDOWN_SORT_DIRECTION); ?>"
		}
		);

		this.m_obj_Layout.store.set_ExtraParams(
		{
			<?php
	print($obj_TABLE_Drop_Down->get_Column_Name($obj_TABLE_Drop_Down->m_int_COL_ID));
?>	: "<?php print(cTABLE_Drop_Down::C_STR_DROPDOWN_SEARCH_LAYOUT); ?>"
		}
		);

		this.callParent();

		this.add(this.m_obj_Sort);
		this.add(this.m_obj_Direction);
		this.add(this.m_obj_Layout);

	},
	activate_Controls	: function()
	{
		this.m_obj_Sort.enable();
		this.m_obj_Direction.enable();
		this.m_obj_Layout.enable();
	},

	set_Field			: function(str_Field)
	{
		this.m_obj_Sort.setValue(str_Field);
	},

	set_Direction		: function(str_Dir)
	{
		this.m_obj_Direction.setValue(str_Dir.toLowerCase());
	},

	get_Field			: function()
	{
		var str_Field = this.m_obj_Sort.getValue();
		if (!str_Field)
		{
			str_Field = "";
		}
		return str_Field;
	},

	get_Direction		: function()
	{
		var str_Dir = this.m_obj_Direction.getValue();
		if (!str_Dir)
		{
			str_Dir = "asc";
		}
		return str_Dir;
	},

	get_Layout			: function()
	{
		var str_Layout = this.m_obj_Layout.getValue();
		if (!str_Layout)
		{
			str_Layout = "standard";
		}
		return str_Layout;
	}
}
);